window.onload=function () {
    layui.use(['table','layer','jquery'],function(){
        var table = layui.table,layer = layui.layer,$ = layui.jquery;
        table.render({
            elem:"#content",
            url:"",
            cols:[[
                {type:'numbers', width:100, title: '编号'},
                {field:'title', width:540, title: '文章标题'},
                {field:'type', width:300, title: '文章类型',templet:function(item){getType(item.type)}},
                {field:'', width:150, title: '操作',toolbar: '#operation'},
            ]]
        })
        table.on('tool(operation)',function(obj){
            var data = obj.data;
            var layEvent = obj.event;
            if(layEvent === 'lookup'){
                location.href = '/content/select?id='+data.id;
            }else if(layEvent === 'modify'){
                location.href = '/content/updata?id='+data.id;
            }else if(layEvent === 'delate'){
                Utils.layer.confirm('是否删除该文章？', {
                    btn: ['是的','不要']
                }, function(){
                    $.post("/content/del",{id:data.id},function(res){
                        if(res.code==200){
                            Utils.layer.msg('删除成功', {icon: 1});
                        }else{
                            Utils.layer.msg(data.msg);
                        }
                    })
                }, function(){});
            }
        })
    })

    function getType(e){
        if(e=='1'){return '关于我们'}
        else if(e=='2'){return '常见问题'}
        else if(e=='3'){return '免责申明'}
    }
}